<?php

require_once dirname(dirname(__FILE__)) . '/config/config.php';
require_once DOCUMENT_ROOT . DIR_SHARED_CONFIG . 'db_connection.php';
require_once DOCUMENT_ROOT . DIR_SHARED_LIBRARIES . 'lib_redirect.php';

class dao_adbox {

    public function save($url, $img) {
        $db = new db_connection();
        $con = $db->open_connect();

        if(empty($url)){
            $url = LINK_ROOT;
        }
        
        $query = "UPDATE tbl_adbox SET url = '" . $url . "', img = '" . $img . "' WHERE id = 1";
        
        mysqli_query($con, $query) or die('Query Failed: ' . mysqli_error());

        $db->close_connect($con);
        return TRUE;
    }

    public function get() {
        $db = new db_connection();
        $con = $db->open_connect();

        $query = "SELECT * FROM tbl_adbox WHERE id = 1";
        $result = mysqli_query($con, $query) or die('Query Failed: ' . mysqli_error());
        $row = mysqli_fetch_array($result);

        $db->close_connect($con);
        return $row;
    }

}
